<?php
/**
 * Author panxu
 * Date   2019/8/12 14:42
 */

namespace App\HttpController;

use EasySwoole\EasySwoole\Config;
use EasySwoole\Http\AbstractInterface\Controller;
use duncan3dc\Laravel\BladeInstance;
use EasySwoole\Http\Response;


class Base extends Controller
{


    function index()
    {
        // TODO: Implement index() method.
        $this->actionNotFound('index');
    }


    protected function render($view, array $vars = [])
    {
        $instance = Config::getInstance();
        $conf     = $instance->getConf('LARAVEL');
        $blade    = new BladeInstance($conf['PATH'], $conf['CACHE']);
        $content  = $blade->render($view, $vars);
        return $this->response()->write($content);
    }


    protected function wJson($statusCode = 0, $result = null, $msg = null)
    {
        if (!$this->response()->isEndResponse()) {
            $data = Array(
                "code" => $statusCode,
                "data" => $result,
                "msg" => $msg
            );
            $this->response()->write(json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
            $this->response()->withHeader('Content-type', 'application/json;charset=utf-8');
            $this->response()->withStatus($statusCode);
            return true;
        } else {
            return false;
        }
    }


}